// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import HardModeGame from "./HardModeGame";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Backgound extends cc.Component {

    bg1: cc.Node = null;
    bg2: cc.Node = null;

    // LIFE-CYCLE CALLBACKS:

    onLoad () {

        this.bg1 = cc.find("bg1", this.node);
        this.bg2 = cc.find("bg2", this.node);
    }

    update (dt) {

        if(HardModeGame.inst.playing == false) return;

        let step = 1;

        let h = 1280;

        this.bg1.y -= step;
        this.bg2.y -= step;

        if(this.bg1.y <= -h) {

            this.bg1.y = h;
        }

        if(this.bg2.y <= -h) {

            this.bg2.y = h;
        }
    }
}
